﻿using LanguagePolish.EntityModel;
using LanguagePolish.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LanguagePolish.Views
{
    /// <summary>
    /// Логика взаимодействия для AddStudentView.xaml
    /// </summary>
    public partial class AddStudentView : Window
    {
        private readonly AddStudentViewModel vm;

        public AddStudentView(Student student, bool isEdit = false)
        {
            InitializeComponent();
            vm = new AddStudentViewModel(student, isEdit);
            DataContext = vm;
            UpdateOkButtonState();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            UpdateOkButtonState();
        }

        private void UpdateOkButtonState()
        {
            // активация кнопки ОК в зависимости от валидности данных
            btnOk.IsEnabled = !vm.HasErrors;
        }
    }
}
